package com.yanliang.edu.service.impl;

import com.yanliang.anno.Autowired;
import com.yanliang.anno.Service;
import com.yanliang.anno.Transactional;
import com.yanliang.edu.dao.AccountDao;
import com.yanliang.edu.pojo.Account;
import com.yanliang.edu.service.TransferService;

@Service("transferService")
public class TransferServiceImpl implements TransferService {

    @Autowired(value = "accountDao")
    private AccountDao accountDao;

    @Override
    @Transactional
    public void transfer(String fromCardNo, String toCardNo, int money) throws Exception {
            Account from = accountDao.queryAccountByCardNo(fromCardNo);
            Account to = accountDao.queryAccountByCardNo(toCardNo);

            from.setMoney(from.getMoney()-money);
            to.setMoney(to.getMoney()+money);

            accountDao.updateAccountByCardNo(to);
//            int i = 1/0;
            accountDao.updateAccountByCardNo(from);
    }
}
